﻿// JScript 文件

//////////////////////////////////////光路配置类///////////////////////////////////////////////////

var CtnGrCfg = Class.create();
document.oncontextmenu=function(e){return false;}    //去除系统右键菜单

CtnGrCfg.prototype = 
{
    initialize: function() 
    {
        var tmp = $A(arguments)
        var options = tmp.shift()
         {
               this.name      = options.name      ? options.name      : "_cfg";       //配置对象名称
               this.LyDrawPen = options.LyDrawPen ? options.LyDrawPen : null;         //路由图操作对象
               this.lylistctr = options.lylistctr ? options.lylistctr : null;         //路由信息的list控件
         
               this.onuatt = ""; 
         }
         
        this.LyGInfo              = new Array();                          //存储图形路由信息
        this.LyArray              = new Array();                          //存储数据路由信息
        this.entlay               = enumCtnEntLay.enumOBOX_SS;            //当前配置的设施层默认为设备层
        
        
                
        //向前插入设备
        this.qdbm = "";                              //A端编码
        this.hdbm = "";                              //B端编码
        this.lxzt;                                   //以当前设备为起始设备的路由段的跳接标志 LXZT_Y : 不跳接 LXZT_N：跳接
        this.LXZT_Y = 1; this.LXZT_N   = 0;          //设备路由的状态
           
        
        
        //光路属性
        {
             this.m_GrType = options.grtype      ? options.grtype      :0;                 //光路类型默认为普通光路
             this.QxNum    = options.QxNum       ? options.QxNum        :2;                 //光路纤芯数
        
        }
        
        this.RMenu    =  null;                  //右键菜单操作对象
         
        this.LyColname = "<items>"
                       + "       <colnames>"
                       +"            <xh visible='1' bedit='0'>序号</xh>"
                       +"            <adbm visible='1' bedit='0'>A端设备</adbm>"
                       +"            <addz visible='1' bedit='0'>A端端子</addz>"
                       +"            <adglmc visible='1' bedit='0'>A端光缆</adglmc>"
                       +"            <bdbm visible='1' bedit='0'>B端设备</bdbm>"
                       +"            <bdkh visible='1' bedit='0'>B端端子</bdkh>"
                       +"            <bdglmc visible='1' bedit='0'>B端光缆</bdglmc>"
                       +"        </colnames>";   //路由详细信息_表头信息

    }
    //private
    ,
    Jmpsb       : Jmpsb_cfg          //找跨跳接设备的回调函数
    ,
    JmpsbQuery  : JmpsbQuery_cfg     //没找到跳接设备时（这时会选择是否条件查询一设备） 查询跳接设备的回调函数
       //事件交互
    ,    
    onRClick    : onRClick_GqGr      //光交设备实体的右键响应函数
    
    
    
    //public
    ,
    QsCfg       : QsCfg_GqGr         // 起始配纤
    ,
    TlCheck     : TlCheck_GqGr       //通路检查
    ,
    ShowCfg     : ShowCfg_GqGr       //显示配置（起始配置和两端配置）的结果
    ,
    TuXCfg      : TuXCfg_GqGr        //图形配置回调函数
    ,
    XqCfg       : XqCfg_GqGr         //向前配置回调函数
    ,
    XhCfg       : XhCfg_GqGr         //向后配置回调函数
    ,
    SetLyXml    : SetLyXml_GqGr     //增加路由详情
    ,
    DrawEntity  : DrawEntity_GqGr   //画路由函数
    ,
    PushLyInfo   : PushLyInfo_GR
    ,
    SetLyxxTx     : SetLyxxTx_GqGr  //设置m_vXhArray,m_vEntArray,m_vBmArray属性值，为画路由做准备,图形
    ,    
    SetLyxxQh     : SetLyxxQh_GqGr  //设置m_vXhArray,m_vEntArray,m_vBmArray属性值，为画路由做准备，向前向后配置
    ,
    GetLyInFoXml: GetLyInFoXml_GrGl
    ,
    deleteLy      : deleteLy_GqGr     //删除路由
    ,
    ShowLyinfo    : ShowLyinfo_GrGl //将路由详情显示在ListCtrl中
    ,
    EditQx        : EditQx_GrGl     //修改纤芯回调函数
    ,
    TlCheckCallb       : TlCheckCallb_GrGl     //通路检查回调函数
    ,
    GetFontBm     : GetFontBm_GrGl   //根据编码得到前实体的编码
    ,
    MiddleSb      : MiddleSb_GrGl   // 向前插入设备回调函数
    ,
    GetZjbm       : GetZjbm_GrGl    //获取中间设备
    ,
    HasJxgq       : HasJxgq_GrGl    //判断两设备之间是否存在局向光纤
    ,
    InsertSb      : InsertSb_GrGl //向中间插入设施和路由
    ,
    InsertLy      : InsertLy_GrGl //向中间插入设施和路由
    ,
    Editbjmp      : Editbjmp_GrGl   //修改设备的bjmp属性
    ,
    IsCenti       : IsCenti_GrGl    
    ,
    IsHeadsb      : IsHeadsb_GrGl   //判断是否是第一个设备
    ,
    InsertHead    : InsertHead_GrGl
    ,
    InsertHeadLy  : InsertHeadLy_GrGl
    ,
    Getnumly      : Getnumly_GrGl   //根据编码得到后面局向光纤的条数
    ,
    Delallback    : Delallback_GrGl
    ,
    ReSetXh       : ReSetXh_GrGl    //序列化序号    ,
    GetSaveLyXml  : GetSaveLyXml_GrGl 
    ,
    GetSaveGrXml  : GetSaveGrXml_GrGl

}


function GetSaveGrXml_GrGl()
{
     var xml = "<?xml version='1.0' encoding='gb2312' ?> ";
    
     xml += "<items><item>";
     xml += "<bm>"     + m_GrBm   + "</bm>";
     xml += "<mc></mc>"
     xml += "<oldbm>"  + m_oldbm  + "</oldbm>"
     xml += "<ywmc>"   + m_ywmc   + "</ywmc>"
     xml += "<jtywlx>" + m_jtywlx + "</jtywlx>"
     xml += "<yhsbh>"  + m_yhsbh  + "</yhsbh>"
     xml += "<cbsx>"   + m_cbsx   + "</cbsx>"
     xml += "<grqs>"   + m_grqs   + "</grqs>"
     xml += "</item></items>";
     return xml;        
}             

//得到保存的路由xml列表

function GetSaveLyXml_GrGl()
{
    var xml = "<?xml version='1.0' encoding='gb2312' ?> ";
    
    xml += "<items>";
    
    this.ReSetXh();
    for(var i = 0; i < this.LyArray.length; i++)
    {
        var tmpObj = this.LyArray[i];
        
        xml += "<item>"
             + "<xh>" +tmpObj.xh+ "</xh>"
             + "<adbm>" +tmpObj.adbm+ "</adbm>"
             + "<adkh>" +tmpObj.adkh+ "</adkh>"
             + "<addz>" +tmpObj.addz+ "</addz>"
             + "<bdbm>" +tmpObj.bdbm+ "</bdbm>"
             + "<bdkh>" +tmpObj.bdkh+ "</bdkh>"
             + "<bddz>" +tmpObj.bddz+ "</bddz>"
             + "</item>";
    }
    xml += "</items>";

    return xml; 
}


//起始配纤

function QsCfg_GqGr()
{
	top.ExecuteATool(top.m_vt.FUN_QUEGJSB,[this.m_GrType,this.ShowCfg.bind(this),true])
	
	//top.CtnDlg.open("GqGr/GrLyMap.aspx?grbm="+""+"&GrType="+""+"&blogicmap="+0, {title:"光路路由图",width:800,height:550,arrbtn:[{text:"关 闭",onClick:function(dlg){dlg.close();}}]});

}

//通路检查

function TlCheck_GqGr()
{
     var params = [this.m_GrType,this.QxNum,null,null,null,null,null,this.TuXCfg.bind(this)];
     top.ExecuteATool(m_vt.MAP_TLCHECK,params)
}

//显示配置结果

function ShowCfg_GqGr(dlg,cfgType)   //cfgType配置类型 0 图形配纤 1 手动配纤
{
    var res = dlg.wnd.ReturnVal();
  
    if(res)
    {
        this.entlay = res.entlay;    //选择设备的同时也选择的设施层
        if(cfgType == 1)
        {
            var StClass = {bm:res.bm,mc:res.mc,devtype:res.devtype,bjmp:false};
            this.LyGInfo.push(StClass);
            this.DrawEntity();            
        }
        else
        {
            var params = [this.m_GrType,this.QxNum,this.entlay,1,res.bm,this.TuXCfg.bind(this)];
            top.ExecuteATool(top.m_vt.MAP_JXGQMAP,params)
        }
    }
    dlg.close();
}


//右键响应消息

function onRClick_GqGr(obj,objtype)
{
    
    this.RMenu = new CtnMenuCtrl(this.name + ".RMenu");   
    if(objtype == "pnt")
    {
        var entbm = obj.id;
        var endbm = this.GetFontBm(entbm);
        this.qdbm = entbm;
        this.hdbm = endbm;
        with(this.RMenu)        
        {
            addEvent("向前配置",this.name + ".IsCenti('"+entbm+"',1,"+this.m_GrType+","+this.QxNum+")");
            addEvent("<hr>","");
            if(this.IsHeadsb(entbm))
            {
                addEvent("向后配置","top.ExecuteATool(top.m_vt.FUN_SELAJXGQ,['向后配置',"+this.m_GrType+","+null+",'"+entbm+"',"+null+","+this.entlay+","+this.QxNum+","+this.name+".XhCfg.bind("+this.name+")])");
            }
            addEvent("跨设备跳接", this.name + ".IsCenti('"+entbm+"',3)");
            addEvent("删除设施",   this.name + ".deleteLy('"+entbm+"')");
            addEvent("出逻辑图",   this.name + ".IsCenti('"+entbm+"',5)");
            addEvent("通路检查",   this.name + ".IsCenti('"+entbm+"',4)");
            if(endbm != false)
            {
                addEvent("向前插入设备","GetMiddleSb('"+entbm+"','"+endbm+"',"+this.QxNum+","+this.name+".MiddleSb.bind("+this.name+"))")
            }
        }
    }
    else
    {
        var frontbm = this.LyDrawPen.drawPen.getObjAtt(obj,"frontbm");
        var endbm = this.LyDrawPen.drawPen.getObjAtt(obj,"endbm");
        with(this.RMenu)
        {
            addEvent("修改纤芯","top.ExecuteATool(top.m_vt.FUN_SELAJXGQ,['修改纤芯',"+this.m_GrType+",'"+frontbm+"','"+endbm+"',"+this.entlay+","+this.entlay+","+this.QxNum+","+this.name+".EditQx.bind("+this.name+")])")
        }
    }
    this.RMenu.show();
}
//跨设备跳接回调函数//如果是Epon光路,obd设备的跳接要把跳接当成一路由段
function Jmpsb_cfg(dlg,ishave)
{
    var enumdevtype = enumCtnOBoxType.enumOBOX_NULL; 


    if(ishave)  //如果没有找到跳接的下一设备则选择一设备跳接
    {
       top.CtnDlg.open("GqGr/Query.aspx?GrType=" + this.m_GrType + "&dispType="+0, {title:"光交设备查询",width:700,height:500,arrbtn:[{text:"确定",onClick:this.JmpsbQuery.bind(this)},{text:"取消",onClick:function(dlg){dlg.close();}}]});
    }
    else
    {
      var res = dlg.wnd.ReturnVal()
      var StClass = {bm:res.bm,mc:res.mc,devtype:res.enttype,bjmp:true};
      
      enumdevtype = GetGjsbTypeVal(parseInt(dlg.entbm));
      
//      if(parseInt(res.enttype) == enumCtnOBoxType.enumOBOX_POS || parseInt(res.enttype) == enumCtnOBoxType.enumOBOX_MPOS || enumdevtype == enumCtnOBoxType.enumOBOX_POS || enumdevtype == enumCtnOBoxType.enumOBOX_MPOS)
//      {
//           StClass.bjmp = false;               //图形表示为非跳接
//           var ly = new LyInFoObj();
//            ly.bdtype = enumdevtype;
//            ly.bdbm   = res.bm;
//            ly.bdmc   = res.mc;
//            ly.bdkh   = "";
//            ly.bddz   = "";
//           
//            ly.adtype = GetGjsbTypeVal(parseInt(dlg.entbm));
//            ly.adbm   = dlg.entbm;
//            ly.admc   = "";
//            ly.adkh   = "";
//            ly.addz   = dlg.dzbm;
//          
//            this.LyArray.push(ly);
//      }
      this.LyGInfo.push(StClass);
      this.DrawEntity();         
      
      var strxml = this.GetLyInFoXml();
      this.ShowLyinfo(strxml);
    
      dlg.close();
    }
}


//查询跳接的下一设备

function JmpsbQuery_cfg(dlg)
{
    var res = dlg.wnd.ReturnVal()
    var StClass = {bm:res.bm,mc:res.mc,devtype:res.entlay,bjmp:true};
    this.LyGInfo.push(StClass);
    this.DrawEntity();         
    dlg.close();
}

//图形配置回调函数

function TuXCfg_GqGr(res)
{
    var split = res.split('||');
    var lyxml = split[0];
    this.onuatt = split[1] || "";
    
    top.m_doc.setActive(top.m_vt.GQGRGL_GRCFG);
    this.SetLyxxTx(lyxml);
    this.DrawEntity();
    var strxml = this.GetLyInFoXml();
    this.ShowLyinfo(strxml);
}

//向前配置回调函数

function XqCfg_GqGr(dlg)
{
    var res = dlg.wnd.ReturnVal();
    this.SetLyxxQh(res);    
    this.DrawEntity();
    var strxml = this.GetLyInFoXml();
    this.ShowLyinfo(strxml)
    dlg.close(); 
}

//向后配置回调函数


function XhCfg_GqGr(dlg)
{
    var res = dlg.wnd.ReturnVal();
    var xmlDoc = CtnXML.getXmlDoc();
    if (xmlDoc!==null)
    {
        xmlDoc.loadXML(res);
    }
    var resItems = xmlDoc.selectNodes("items/item");
    for(var i = 0;i<resItems.length;i++)
    {
        var LyList = resItems[i];
        var bdbm = LyList.selectNodes("ly/bdbm");
        var bdmc = LyList.selectNodes("ly/bdmc");
        var bdtype = LyList.selectNodes("ly/bdtype");
        var bdStClass = {bm:bdbm[0].text,mc:bdmc[0].text,devtype:bdtype[0].text,bjmp:false};
        this.InsertHead(bdStClass);
        var ResLy = resItems[i].selectNodes("ly");
        this.InsertHeadLy(ResLy);
    }
    
    this.DrawEntity();
    var strxml = this.GetLyInFoXml();
    this.ShowLyinfo(strxml)
    dlg.close(); 
} 


function InsertHead_GrGl(bdStClass)
{
    var temparr = new Array();
    var bmarrl = this.LyGInfo.length;
    var i = 0;
    for(i = 0;i<bmarrl;i++)
    {
        temparr.push(this.LyGInfo[i]);
    }
    for(i = 0;i<bmarrl;i++)
    {
        this.LyGInfo.pop();
    }
    this.LyGInfo.push(bdStClass);
    for(i = 0;i<bmarrl;i++)
    {
        this.LyGInfo.push(temparr[i]);
    }
}


function InsertHeadLy_GrGl(ResLy)
{
    var temparr = new Array();
    var bmarrl = this.LyArray.length;
    var i = 0;
    for(i = 0;i<bmarrl;i++)
    {
        temparr.push(this.LyArray[i]);
    }
    for(i = 0;i<bmarrl;i++)
    {
        this.LyArray.pop();
    }
    for(var j = 0;j<ResLy.length;j++)
    {
        var LyinfoList = new LyInFoObj();
        LyinfoList.SetInfoxh(ResLy[j]);
        this.LyArray.push(LyinfoList);
    }
    for(i = 0;i<bmarrl;i++)
    {
        this.LyArray.push(temparr[i]);
    }
}
//修改纤芯回调函数
function EditQx_GrGl(dlg)
{
    var res = dlg.wnd.ReturnVal();
    var xmlDoc = CtnXML.getXmlDoc();
    if (xmlDoc!==null)
    {
        xmlDoc.loadXML(res);
    }
    var resItems = xmlDoc.selectNodes("items/item");
    var LyListo = resItems[0].selectNodes("ly")[0];
    var LyListt = resItems[0].selectNodes("ly")[1];
    var adbm = $XML(LyListo.selectSingleNode("adbm"));
    for(var i = 0;i<this.LyArray.length;i++)
    {
        if(this.LyArray[i].adbm == adbm)
        {
            if(this.QxNum == 1)
            {
                this.LyArray[i].adkh   = $XML(LyListo.selectSingleNode("adkh")) || "";
                this.LyArray[i].addz   = $XML(LyListo.selectSingleNode("addz")) || "";
                this.LyArray[i].adglqx = $XML(LyListo.selectSingleNode("adglqx")) || "";
                this.LyArray[i].bdkh   = $XML(LyListo.selectSingleNode("bdkh")) || "";
                this.LyArray[i].bddz   = $XML(LyListo.selectSingleNode("bddz")) || "";
                this.LyArray[i].bdglqx = $XML(LyListo.selectSingleNode("bdglqx")) || "";
            }
            else
            {
                this.LyArray[i].adkh = $XML(LyListo.selectSingleNode("adkh")) || "";
                this.LyArray[i].addz = $XML(LyListo.selectSingleNode("addz")) || "";
                this.LyArray[i].adglqx = $XML(LyListo.selectSingleNode("adglqx")) || "";
                this.LyArray[i].bdkh = $XML(LyListo.selectSingleNode("bdkh")) || "";
                this.LyArray[i].bddz = $XML(LyListo.selectSingleNode("bddz")) || "";
                this.LyArray[i].bdglqx = $XML(LyListo.selectSingleNode("bdglqx")) || "";
                
                this.LyArray[i + 1].adkh = $XML(LyListt.selectSingleNode("adkh")) || "";
                this.LyArray[i + 1].addz = $XML(LyListt.selectSingleNode("addz")) || "";
                this.LyArray[i + 1].adglqx = $XML(LyListt.selectSingleNode("adglqx")) || "";
                this.LyArray[i + 1].bdkh = $XML(LyListt.selectSingleNode("bdkh")) || "";
                this.LyArray[i + 1].bddz = $XML(LyListt.selectSingleNode("bddz")) || "";
                this.LyArray[i + 1].bdglqx = $XML(LyListt.selectSingleNode("bdglqx")) || "";
            }        
            break;   
        }
    }
    var strxml = this.GetLyInFoXml();
    this.ShowLyinfo(strxml);
    dlg.close(); 
}
//通路检查回调函数
function TlCheckCallb_GrGl(res)
{
    top.m_doc.setActive(top.m_vt.GQGRGL_GRCFG);
    this.SetLyxxQh(res);    
    this.DrawEntity();
    var strxml = this.GetLyInFoXml();
    this.ShowLyinfo(strxml)
    //top.m_doc.removeWnd(top.m_vt.MAP_TLCHECK);
}


function GetZjbm_GrGl(dlg)
{
    var res = dlg.wnd.ReturnVal()
    
    var abzt = this.HasJxgq(this.qdbm,res.bm);     //检查第一段是否有局向光纤
    if(abzt == "1")
    {
        top.ExecuteATool(top.m_vt.FUN_SELAJXGQ,["选择纤芯",this.m_GrType,this.qdbm,res.bm,this.entlay,this.entlay,this.QxNum,this.InsertLy.bind(this)])
        var StClass = {bm:res.bm,mc:res.mc,devtype:res.enttype,bjmp:false};
        this.InsertSb(StClass)
        this.Editbjmp(this.hdbm,true);
    }
    else if(this.HasJxgq(res.bm,this.hdbm) == "1")   //检查第二段是否有局向光纤
    {
        top.ExecuteATool(top.m_vt.FUN_SELAJXGQ,["选择纤芯",this.m_GrType,res.bm,this.hdbm,this.entlay,this.entlay,this.QxNum,this.InsertLy.bind(this)])
        var StClass = {bm:res.bm,mc:res.mc,devtype:res.enttype,bjmp:true};
        this.InsertSb(StClass)
    }
    else
    {
        var StClass = {bm:res.bm,mc:res.mc,devtype:res.entlay,bjmp:true};
        this.InsertLy();
        this.InsertSb(StClass);
        this.Editbjmp(this.hdbm,true);
    }
    this.DrawEntity();
    var strxml = this.GetLyInFoXml();
    this.ShowLyinfo(strxml)
    dlg.close();
}
function InsertSb_GrGl(midobj)
{
    var hdarray = new Array();  
    var sblength = this.LyGInfo.length;
    for(var i = 0;i<sblength;i++)
    {
        var sbobj = this.LyGInfo.pop();
        hdarray.push(sbobj);
        if(sbobj.bm == this.qdbm)
        {
            this.LyGInfo.push(sbobj);
            hdarray.pop();
            break;
        }
    }
    this.LyGInfo.push(midobj);
    for(var j = hdarray.length-1;j>=0;j--)
    {
        this.LyGInfo.push(hdarray[j]);
    }
}
function MiddleSb_GrGl(dlg)
{
    if(dlg)
    {
        var res = dlg.wnd.ReturnVal();
        var xmlDoc = CtnXML.getXmlDoc();
        if (xmlDoc!==null)
        {
            xmlDoc.loadXML(res);
        }
        var resItems = xmlDoc.selectNodes("items/item");
        var LyList = resItems[0].selectNodes("ly")[0];
        var objbm = LyList.selectNodes("bdbm");
        var objmc = LyList.selectNodes("bdmc");
        var objype = LyList.selectNodes("bdtype");
        var adStClass = {bm:objbm[0].text,mc:objmc[0].text,devtype:objype[0].text,bjmp:false};
        this.lxzt = QsCfg.LXZT_Y;
        this.InsertSb(adStClass);
        this.InsertLy(res);
        this.Editbjmp(this.hdbm,false);
        this.DrawEntity();
        var strxml = this.GetLyInFoXml();
        this.ShowLyinfo(strxml)
        dlg.close();
    }
    else
    {
        top.CtnDlg.open("GqGr/Query.aspx?GrType="+this.m_GrType+"&dispType="+0, {title:"光交设备查询",width:700,height:500,arrbtn:[{text:"确定",onClick:this.GetZjbm.bind(this)},{text:"取消",onClick:function(dlg){dlg.close();}}]});
    }
}

//检查两设备之间是否有局向光纤

function HasJxgq_GrGl(adbm,bdbm)
{
    var vParam = "_method=bHasJxgq&qsent="+adbm + "&zzent=" + bdbm;
    var res = top.CtnTrans.getText("/main.ashx", "post", vParam)
    return res;
}
function InsertLy_GrGl(res)
{
    var lylength = this.Getnumly(this.qdbm);
    var lytemp = new Array();
    for(var k = 0;k<lylength;k++)
    {
        if(this.QxNum == 1)
        {
            var tempobj = this.LyArray.pop();
        }
        else
        {
            var tempobj = this.LyArray.pop();
            this.LyArray.pop();
        }
        lytemp.push(tempobj);
    }
    if(this.lxzt == this.LXZT_Y)
    {
        if(this.QxNum == 1)
        {
            lytemp.pop();
        }
        else
        {
            lytemp.pop();
            lytemp.pop();
        }
    }
    if(res)
    {
        var xmlDoc = CtnXML.getXmlDoc();
        if (xmlDoc!==null)
        {
            xmlDoc.loadXML(res);
        }
        var resItems = xmlDoc.selectNodes("items/item");
        for(var i = 0;i<resItems.length;i++)
        {
            var ResLy = resItems[i].selectNodes("ly");
            
            for(var j = 0;j<ResLy.length;j++)
            {
                var LyinfoList = new LyInFoObj();
                LyinfoList.SetInfo(ResLy[j]);
                this.LyArray.push(LyinfoList);
            }
        }
    }
    for(var n = lytemp.length-1;n>=0;n--)
    {
        this.LyArray.push(lytemp[n]);
    }
}
function ShowLyinfo_GrGl(strxml)
{
    this.lylistctr.reset();
    this.lylistctr.insertXml(strxml, 1);
    this.lylistctr.show();  
}
function DrawEntity_GqGr()
{
    if(this.LyDrawPen.layer.length == 0 && this.LyGInfo.length != 0)
    {
        var StObj = {devinfolist:this.LyGInfo};             
        this.LyDrawPen.insertInfo(StObj);
        $("divly").innerHTML = "";
    }
    $("divly").innerHTML = "";
    this.LyDrawPen.Draw();
}
function deleteLy_GqGr(Entitybm)
{
    if(confirm("请确认，是否要删除"))
    {
        var Tbjmp = false;
        var Stnum = 0;
        for(var j = 0;j<this.LyGInfo.length;j++)
        {
            if(this.LyGInfo[j].bm == Entitybm)
            {
                Tbjmp = true;
                if(j == 0)
                {   
                    if(this.LyGInfo.length == 1)
                    {
                        this.LyGInfo.pop();
                    }
                    else if(this.LyGInfo[j+1].bjmp == false)
                    {
                        this.LyGInfo.splice(0,1);
                        if(this.QxNum == 1)
                        {
                            this.LyArray.splice(0,1);
                        }
                        else
                        {
                            this.LyArray.splice(0,1);
                            this.LyArray.splice(0,1);
                        }
                    }
                    else
                    {
                        this.LyGInfo.splice(0,1);
                    }
                    Tbjmp = false;
                    break;
                }
            }
            if(Tbjmp && this.LyGInfo[j].bjmp == false)
            {
                Stnum++;
            }
        }
        for(var k = 0;k<Stnum;k++)
        {
            if(this.QxNum == 1)
            {
                this.LyArray.pop();
            }
            else
            {
                this.LyArray.pop();
                this.LyArray.pop();
            }
        }
        if(Tbjmp)
        {
            for(var i = 0;i<this.LyGInfo.length;i++)
            {
                var pntbm = this.LyGInfo.pop().bm;
                if(Entitybm == pntbm)
                {
                    break;
                }
            }
        }
        this.DrawEntity();
        var strxml = this.GetLyInFoXml();
        this.ShowLyinfo(strxml);
    }
}


//<items><item><ly><xh></xh><adtype></adtype><adbm></adbm><admc></admc><adkh></adkh>...</ly>...</item></items>
//路由信息置入缓存
function PushLyInfo_GR(xml)
{
     var xmlDoc = CtnXML.getXmlDoc();
     if (xmlDoc == null)
     {
        alert("初始化xml对象失败！"); 
        return;
     }
     
     this.QxNum = 1; 
     var prexh = "";
     var prebm = ""; 
     
     xmlDoc.loadXML(xml);
     var nodes =  xmlDoc.selectNodes("items/item/ly");
    
     //存储图形信息 
     for(var i = 0; i < nodes.length; i++)
     {
        var bjump = false; 
        var xh = $XML(nodes[i].selectSingleNode("xh"));
        var bdbm   = $XML(nodes[i].selectSingleNode("bdbm"));
         
        if(xh == prexh)
        {
            this.QxNum = 2;
            if(i == nodes.length - 1)
            {
                var bdmc   = $XML(nodes[i].selectSingleNode("bdmc"));
                var bdtype = $XML(nodes[i].selectSingleNode("bdtype"));
                
                this.LyGInfo.push({bm:bdbm,mc:bdmc,devtype:bdtype,bjmp:false});
            }
            continue;    //如果是双纤设备信息取一次够了
        }
        var adbm   = $XML(nodes[i].selectSingleNode("adbm"));
        var admc   = $XML(nodes[i].selectSingleNode("admc"));
        var adtype = $XML(nodes[i].selectSingleNode("adtype"));
        
        if(prebm != adbm)
        {
            bjump = true; 
        }
        this.LyGInfo.push({bm:adbm,mc:admc,devtype:adtype,bjmp:bjump});
        
         if(i == nodes.length - 1)
         {
              var bdmc   = $XML(nodes[i].selectSingleNode("bdmc"));
              var bdtype = $XML(nodes[i].selectSingleNode("bdtype"));
                
              this.LyGInfo.push({bm:bdbm,mc:bdmc,devtype:bdtype,bjmp:false});
         }
            
        prebm = bdbm;
        prexh = xh;
     }   
     //存储数据路由信息 
     this.SetLyXml(nodes);
}


//<items><item><ly><xh></xh><adtype></adtype><adbm></adbm><admc></admc><adkh></adkh>...</ly></item>...</items>

//将路由信息存入缓存 LyGInfo 该xml是类似从局向光纤逻辑图返回的路由信息

function SetLyxxTx_GqGr(res)
{
    var xmlDoc = CtnXML.getXmlDoc();
    if (xmlDoc!==null)
    {
        xmlDoc.loadXML(res);
    }
    
    var preBm = "";
    var bjump = false;
    var resItems = xmlDoc.selectNodes("items/item");
    for(var i = 0;i<resItems.length;i++)
    {
        var LyList = resItems[i].selectNodes("ly")[0];
        if(!LyList){return;}
        var adbm = LyList.selectNodes("adbm");
        var admc = LyList.selectNodes("admc");
        var adtype = LyList.selectNodes("adtype");
        
        if($XML(adbm[0]) != preBm && preBm != "")
        {
            bjump = true;
        }
        preBm = $XML(LyList.selectNodes("bdbm")[0]);
        var adStClass = {bm:$XML(adbm[0]),mc:$XML(admc[0]),devtype:$XML(adtype[0]),bjmp:bjump};
        this.LyGInfo.push(adStClass);
        if(i == resItems.length-1)
        {
            var bdbm = LyList.selectNodes("bdbm");
            var bdmc = LyList.selectNodes("bdmc");
            var bdtype = LyList.selectNodes("bdtype");
            var bdStClass = {bm:$XML(bdbm[0]),mc:$XML(bdmc[0]),devtype:$XML(bdtype[0]),bjmp:false};
            this.LyGInfo.push(bdStClass);
        }
        var ResLy = resItems[i].selectNodes("ly");
        this.SetLyXml(ResLy);
    }
}


function SetLyxxQh_GqGr(res)
{
    var xmlDoc = CtnXML.getXmlDoc();
    if (xmlDoc!==null)
    {
        xmlDoc.loadXML(res);
    }
    var resItems = xmlDoc.selectNodes("items/item");
    for(var i = 0;i<resItems.length;i++)
    {
        var LyList = resItems[i];
        var bdbm = LyList.selectNodes("ly/bdbm");
        var bdmc = LyList.selectNodes("ly/bdmc");
        var bdtype = LyList.selectNodes("ly/bdtype");
        var bdStClass = {bm:bdbm[0].text,mc:bdmc[0].text,devtype:bdtype[0].text,bjmp:false};
        this.LyGInfo.push(bdStClass);
        var ResLy = resItems[i].selectNodes("ly");
        this.SetLyXml(ResLy);
    }
}
function SetLyXml_GqGr(ResLy)
{
    for(var j = 0;j<ResLy.length;j++)
    {
        var LyinfoList = new LyInFoObj();
        LyinfoList.SetInfo(ResLy[j]);
        this.LyArray.push(LyinfoList);
    }
}

//检查当前设备是否为第一个设备

function IsHeadsb_GrGl(bm)
{
    for(var i = 0;i<this.LyGInfo.length;i++)
    {
        if(this.LyGInfo[i].bm == bm && i == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    return false;
}

//右键菜单消息控制函数

function IsCenti_GrGl(bm,whick)
{
    
    var Ishave = this.GetFontBm(bm)
    if(Ishave) //不是最后一个设备
    {
        //CtnDlg.confirm("此操作将会删除当前设备前面的设备，确认是否删除?",this.Delallback.bind(this),[bm,whick,this.m_GrType,this.QxSum]);
        if(confirm("此操作将会删除当前设备前面的设备，确认是否删除？"))
        {
            this.Delallback(true,["",""]);
        }
        
    }
//    else
//    {
        switch(whick)
        {
            case 1: top.ExecuteATool(top.m_vt.FUN_SELAJXGQ,["向前配置",this.m_GrType,bm,  null,this.entlay,null,       this.QxNum,this.XqCfg.bind(this)]);break;
            case 2: top.ExecuteATool(top.m_vt.FUN_SELAJXGQ,["向后配置",this.m_GrType,null,bm,  null,       this.entlay,this.QxNum,this.XhCfg.bind(this)]);break;
            case 3: top.ExecuteATool(m_vt.QUERY_JMPSB,[bm,this.Jmpsb.bind(this),0,0,10]);break;
            case 4: top.ExecuteATool(m_vt.MAP_TLCHECK,[this.m_GrType,this.QxNum,bm,null,null,null,null,this.TlCheckCallb.bind(this)]);break;
            case 5: top.ExecuteATool(m_vt.MAP_JXGQMAP,[this.m_GrType,this.QxNum,enumCtnEntLay.enumOBOX_SS,1,bm,this.TlCheckCallb.bind(this)]);break;
        }
    //}
}

//删除当前设备前面的设备

function Delallback_GrGl(res,params)
{
    if(res)
    {
        var bm = params[0];
        var GrType = params[2];
        var Qx = params[3];
        var i = 0;
        var bmlength = this.LyGInfo.length;
        var temp = false;
        var sxnum = 0;
        for(i = 0;i<bmlength;i++)
        {
            if(temp && this.LyGInfo[i].bjmp == false)
            {
                sxnum++;
            }
            if(this.LyGInfo[i].bm == params[0])
            {
                temp = true;
            }
        }
        for(i = 0;i<sxnum;i++)
        {
            if(this.Qx == 1)
            {
                this.LyArray.pop();
            }
            else
            {
                this.LyArray.pop();
                this.LyArray.pop();
            }
        }
        for(i = 0;i<bmlength;i++)
        {
            var obj = this.LyGInfo.pop();
            if(obj.bm == bm)
            {
                this.LyGInfo.push(obj);
            }
        }
        
        switch(params[1])
        {
            case 1: top.ExecuteATool(top.m_vt.FUN_SELAJXGQ,["向前配置",this.m_GrType,bm,  null,this.entlay,null,       this.QxNum,this.XqCfg.bind(this)]);break;
            case 2: top.ExecuteATool(top.m_vt.FUN_SELAJXGQ,["向后配置",this.m_GrType,null,bm,  null,       this.entlay,this.QxNum,this.XhCfg.bind(this)]);break;
            case 3: top.ExecuteATool(m_vt.QUERY_JMPSB,[bm,this.Jmpsb.bind(this),0,0,10]);break;
            case 4: top.ExecuteATool(m_vt.MAP_TLCHECK,[this.m_GrType,this.QxNum,bm,null,null,null,null,this.TlCheckCallb.bind(this)]);break;
            case 5: top.ExecuteATool(m_vt.MAP_JXGQMAP,[this.m_GrType,this.QxNum,enumCtnEntLay.enumOBOX_SS,1,bm,this.TlCheckCallb.bind(this)]);break;
        }
    }
}

//得到设备前（右）边的局向光纤的个数

function Getnumly_GrGl(bm)
{
    var i = 0;
    var jxnum = 0;
    var temp = false;
    for(i = 0;i<this.LyGInfo.length;i++)
    {
       if(temp && this.LyGInfo[i].bjmp == false)      
       {
           jxnum++;
       }
       if(this.LyGInfo[i].bm == bm)
       {
            temp = true;
       }
    }    
    return jxnum;
}

//构造路由xml

function GetLyInFoXml_GrGl()
{
    var StrXml = this.LyColname;
    var xh = 1;
    for(var i = 0;i<this.LyArray.length;i++)
    {
        var XLyinfo = this.LyArray[i];
        StrXml += "<item>";
        StrXml += "<col>"+xh+"</col>";
        StrXml += "<col>("+XLyinfo.admc+")"+XLyinfo.adbm+"</col>";
        if(XLyinfo.adkh == "")
        {
            StrXml += "<col>"+XLyinfo.addz+"</col>";
        }
        else
        {
            StrXml += "<col>"+XLyinfo.adkh+"/"+XLyinfo.addz+"</col>";
        }
        if(XLyinfo.adglmc == "")
        {
            StrXml += "<col></col>";
        }
        else
        {
            StrXml += "<col>"+XLyinfo.adglmc+"("+XLyinfo.adglqx+"芯)"+"</col>";
        }
        StrXml += "<col>("+XLyinfo.bdmc+")"+XLyinfo.bdbm+"</col>";
        if(XLyinfo.bdkh == "")
        {
            StrXml += "<col>"+XLyinfo.bddz+"</col>";
        }
        else
        {
            StrXml += "<col>"+XLyinfo.bdkh+"/"+XLyinfo.bddz+"</col>";
        }
        if(XLyinfo.bdglmc == "")
        {
                    
            StrXml += "<col></col>";
        }
        else
        {
            
            StrXml += "<col>"+XLyinfo.bdglmc+"("+XLyinfo.bdglqx+"芯)"+"</col>";
        }
        StrXml += "</item>";
        if(this.QxNum == 1)
        {
            xh++;
        }
        else if(this.QxNum == 2 && i%2 == 1)
        {
            xh++;
        }
    }
    StrXml += "</items>";
    return StrXml;
}

// 输入: 设备编码
// 输出: false 改设备是路由中的最后一设备  this.lxzt == this.LXZT_Y 返回当前设备的下一设备，两设备之间是局向光纤关系 

function GetFontBm_GrGl(bm)
{
    var i = 0;
    this.lxzt = this.LXZT_N;
    for(i = 0;i<this.LyArray.length;i++)
    {
        if(bm == this.LyArray[i].adbm)
        {
            this.lxzt = this.LXZT_Y;
            return this.LyArray[i].bdbm;
        }
    }
    for(i = 0;i<this.LyGInfo.length;i++)
    {
        if(this.LyGInfo[i].bm == bm)
        {
            if(i == this.LyGInfo.length-1)
            {
                return false;
            }
            else
            {
                return this.LyGInfo[i+1].bm;
            }
        }
    }
}
function Editbjmp_GrGl(bm,bjmp)
{
    for(var i = 0;i<this.LyGInfo.length;i++)
    {
        if(this.LyGInfo[i].bm == bm)
        {
            this.LyGInfo[i].bjmp = bjmp;
        }
    }
}

//刷新路由序号

function ReSetXh_GrGl()
{
    var lyxh = 1;
    for(var i = 0;i<this.LyArray.length;i++)
    {
        this.LyArray[i].xh = lyxh;
        if(this.QxNum == 1)
        {
            lyxh++;
        }
        else if(this.QxNum == 2 && i%2 == 1)
        {
            lyxh++;
        }
    }
}

var LyInFoObj = Class.create();
LyInFoObj.prototype = 
{
    initialize: function() 
    {
        this.xh = "";
        this.adtype = "";
        this.adbm = "";
        this.admc = "";
        this.adkh = "";
        this.addz = "";
        this.adglmc = "";
        this.adglqx = "";
        this.bdtype = "";
        this.bdbm = "";
        this.bdmc = "";
        this.bdkh = "";
        this.bddz = "";
        this.bdglmc = "";
        this.bdglqx = "";
    }
    ,
    SetInfo     : SetInfo_Ly
    ,
    SetInfoxh   : SetInfoxh_Ly
}
function SetInfo_Ly(ResLy)
{
    this.adtype = GetGjsbTypeVal(parseInt(ResLy.selectNodes("adtype")[0].text)); 
    this.adbm   = ResLy.selectNodes("adbm")[0].text;
    this.admc   = ResLy.selectNodes("admc")[0].text;
    this.adkh   = ResLy.selectNodes("adkh")[0].text;
    this.addz   = ResLy.selectNodes("addz")[0].text;
    this.adglmc = ResLy.selectNodes("adglmc")[0].text;
    this.adglqx = ResLy.selectNodes("adglqx")[0].text;
    this.bdtype = GetGjsbTypeVal(parseInt(ResLy.selectNodes("bdtype")[0].text));
    this.bdbm   = ResLy.selectNodes("bdbm")[0].text;
    this.bdmc   = ResLy.selectNodes("bdmc")[0].text;
    this.bdkh   = ResLy.selectNodes("bdkh")[0].text;
    this.bddz   = ResLy.selectNodes("bddz")[0].text;
    this.bdglmc = ResLy.selectNodes("bdglmc")[0].text;
    this.bdglqx = ResLy.selectNodes("bdglqx")[0].text;
}
function SetInfoxh_Ly(ResLy)
{
    this.bdtype = GetGjsbTypeVal(parseInt(ResLy.selectNodes("adtype")[0].text)); 
    this.bdbm   = ResLy.selectNodes("adbm")[0].text;
    this.bdmc   = ResLy.selectNodes("admc")[0].text;
    this.bdkh   = ResLy.selectNodes("adkh")[0].text;
    this.bddz   = ResLy.selectNodes("addz")[0].text;
    this.bdglmc = ResLy.selectNodes("adglmc")[0].text;
    this.bdglqx = ResLy.selectNodes("adglqx")[0].text;
    this.adtype = GetGjsbTypeVal(parseInt(ResLy.selectNodes("bdtype")[0].text));
    this.adbm   = ResLy.selectNodes("bdbm")[0].text;
    this.admc   = ResLy.selectNodes("bdmc")[0].text;
    this.adkh   = ResLy.selectNodes("bdkh")[0].text;
    this.addz   = ResLy.selectNodes("bddz")[0].text;
    this.adglmc = ResLy.selectNodes("bdglmc")[0].text;
    this.adglqx = ResLy.selectNodes("bdglqx")[0].text;
}